package com.hyt.it.ogt.pj.feign;

import com.hyt.common.apiInfor.ApiResponse;
import com.hyt.common.utils.exception.RemoteRequestExcepton;
import com.hyt.it.ogt.pj.model.dto.StudentExtendDTO;
import com.hyt.it.ogt.pj.model.entity.ApiFail;
import com.hyt.it.ogt.pj.model.entity.PaperItemFile;
import com.hyt.it.ogt.pj.model.entity.Project;
import com.hyt.it.ogt.pj.model.entity.Subject;
import com.hyt.it.ogt.pj.model.param.MarkCandidateParam;
import com.hyt.it.ogt.pj.model.vo.*;
import com.hyt.model.PageParam;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * feign客户端熔断器
 */
@Component
@Slf4j
public class KwClientHystrix implements FallbackFactory<KwClient> {

    @Override
    public KwClient create(Throwable throwable) {
        log.error("# KwClientHystrix", throwable);

        return new KwClient() {
            @Override
            public ApiResponse<PageParam<ProjectVo>> getAllProject(@RequestParam("projectName") String projectName, @RequestParam("markStatus") String markStatus, @RequestParam("current") long current, @RequestParam("size") long size) {
                log.error("获取任务分页数据失败进入熔断");
                return null;
            }

            @Override
            public ApiResponse<Project> getProjectById(@RequestParam("projectId") String projectId) {
                log.error("获取项目信息失败进入熔断");
                return null;
            }

            @Override
            public ApiResponse<List<Subject>> getSubjects(@RequestParam("projectId") String projectId, @RequestParam(value = "admissionNumber", required = false) String admissionNumber) {
                log.error("获取科目失败进入熔断");
                return null;
            }

            @Override
            public ApiResponse<List<PackageDataVO>> getPapers(@RequestParam("projectId") String projectId, @RequestParam("subjectId") String subjectId, @RequestParam(value = "admissionNumber", required = false) String admissionNumber) {
                log.error("获取试卷失败进入熔断");
                return null;
            }

            @Override
            public ApiResponse<List<StudentExtendDTO>> getProjectStudent(@RequestParam("projectId") String projectId, @RequestParam(value = "admissionNumber", required = false) String admissionNumber) {
                log.error("获取考生信息失败进入熔断");
                return null;
            }

            @Override
            public ApiResponse<PageParam<StudentExtendDTO>> getProjectStudentPage(@RequestParam("projectId") String projectId, @RequestParam(value = "current", required = false) Integer current, @RequestParam(value = "size", required = false) Integer size) {
                log.error("分页获取考生信息失败进入熔断");
                return null;
            }

            @Override
            public ApiResponse<List<StudentAnswerVo>> getStudentAnswer(@RequestParam("projectId") String projectId, @RequestParam(value = "admissionNumber", required = false) String admissionNumber) {
                log.error("获取考生答案失败进入熔断");
                return null;
            }

            @Override
            public ApiResponse<List<ObjectiveScoreVO>> getKgScore(@RequestParam("projectId") String projectId, @RequestParam(value = "admissionNumber", required = false) String admissionNumber) {
                log.error("获取考生客观分失败进入熔断");
                return null;
            }

            @Override
            public ApiResponse<ObjectiveScoreVO> getPaperKgScore(String projectId, String admissionNumber, String paperId,
                                                                 Integer paperVersion) {
                log.error("获取考生试卷客观分失败进入熔断");
                return null;
            }

            @Override
            public ApiResponse markCandidate(@RequestBody MarkCandidateParam params) {
                log.error("打标记失败进入熔断");
                return null;
            }

            @Override
            public ApiResponse getIncrementCandidate(@RequestParam("projectId") String projectId) {
                log.error("获取增量考生失败进入熔断");
                return null;
            }

            @Override
            public ApiResponse updateCandidateJudgeState(@RequestBody UpdateCandidateJudgeStateVO updateCandidateJudgeStateVO) {
                log.error("更新考务评卷状态失败进入熔断");
                return null;
            }

            @Override
            public ApiResponse cancelCandidateJudgeState(@RequestParam("projectId") String projectId, @RequestParam("admissionNumbers") List<String> admissionNumbers) {
                log.error("取消标记失败进入熔断");
                return null;
            }

            @Override
            public ApiResponse<List<ApiFail>> apiFailList(@RequestParam("api") String api) {
                log.error("查询api调用失败的参数失败，进入熔断");
                return null;
            }

            @Override
            public ApiResponse<Object> apiFailDelete(@RequestParam("idArrayJson") String idArrayJson) {
                log.error("删除api调用失败的记录失败，进入熔断");
                return null;
            }

            @Override
            public ApiResponse<Object> updateCandidateAbsent(@RequestParam("projectId") String projectId, @RequestParam("admissionNumber") String admissionNumber, @RequestParam("state") Integer state) {
                log.error("设置学生缺席与否失败，进入熔断");
                return null;
            }

            @Override
            public ApiResponse<ObjectiveScoreVO> getKgScoreForPaper(String projectId, String admissionNumber, String paperId, String paperVersion) {
                log.error("获取客观题成绩失败，进入熔断");
                return null;
            }

            @Override
            public ApiResponse<List<PaperItemFile>> getPaperItemFileData(String paperId, String paperVersion) {
                log.error("获取试卷音视频文件列表失败，进入熔断");
                throw new RemoteRequestExcepton("获取试卷音视频文件列表失败");
            }

            @Override
            public void updateStatus(Long id, Integer status, String error) {
                log.error("更新推送评卷数据状态变更失败，进入熔断");
                throw new RemoteRequestExcepton("更新推送评卷数据状态变更失败");
            }

            @Override
            public void delete(Long pushId) {
                log.error("删除推送评卷数据失败，进入熔断");
                throw new RemoteRequestExcepton("删除推送评卷数据失败");
            }
        };
    }
}
